{extend name='public/window' /}

{block name="content"}
<style>
	.layui-upload-drag {
		position: relative;
		padding: 10px;
		border: 1px dashed #e2e2e2;
		background-color: #fff;
		text-align: center;
		cursor: pointer;
		color: #999;

	}

	table {
		border-collapse: collapse;
		text-align: center;
		width: 720px;
		table-layout: fixed !important;
	}

	table td {
		border: 0.5px solid #f1f0f0;
		color: #000000;
		height: 30px;
		font-size: 13px;
		width: 30px;
		white-space: nowrap;
		/* 自适应宽度*/
	}

	table th {
		border: 0.5px solid #f1f0f0;
		color: #000000;
		height: 40px;
		font-weight: 600;
		font-size: 15px;
	}


	table thead th {
		width: 144px;
	}

	input {
		border: none;
		height: 30px;
		text-align: center;
		max-width: 144px;
	}

	.layui-input-block {
		margin-left: 141px;
		min-height: 36px;
	}

	.layui-textarea {
		display: block;
		width: 85%;
		padding-left: 10px;
	}

	.layui-input {
		display: block;
		width: 85%;
		padding-left: 10px;
	}

	.layui-form-label {
		width: 110px;
	}

	.swriperC {
		position: fixed;
		top: 100px;
		left: 50%;
		width: 500px !important;
		text-align: center;
		height: 280px !important;
		margin-left: -250px;
		z-index: 9;
	}

	.layFormC {
		position: relative;
	}

	.maskC {
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1;
		background-color: rgba(0, 0, 0, 0.4);
	}
	.yes {
		color: #ffffff;
		font-size: 14px;
		background-color: #2d8cf0;
		padding: 3px;
		width: 60px;
		border-radius: 5px;
		text-align: center;
		line-height: 24px;
		display: inline-block;
		float: left;
		margin: 20px 0 20px 0;
	}
	
	.no {
		color: #ffffff;
		font-size: 14px;
		background-color: #2d8cf0;
		padding: 3px;
		width: 60px;
		border-radius: 5px;
		text-align: center;
		line-height: 24px;
		display: inline-block;
		float: right;
		margin: 20px 0 20px 0;
	}
</style>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-body" style="padding: 15px;">
			<form class="layui-form layFormC" action="" lay-filter="form">
				{if isset($info.id)}
				<input type="hidden" name="id" value="{$info.id}">
				{/if}
				<input type="hidden" name="__token__" id="token" value="{:token()}" />
				<div class="layui-form-item">
					<label class="layui-form-label">商户类型</label>
					<div class="layui-input-inline">
						<select name="merchant_type" lay-verify="required" id="type_select" lay-filter="merchant_type">
							<option value="1">常驻</option>
							<option value="2">临户</option>
						</select>
					</div>
				</div>
				<div class="layui-form-item merch">
					<label class="layui-form-label ">商户*</label>
					<div class="layui-input-inline">
						<select name="merchant_id" lay-search="" lay-verify="required" id="merchant_id" lay-filter="merchant_id">
							<option value="">请选择</option>
							{volist name="merchant_list" id="t"}
							<option value="{$t.id}">{$t.name} - {$t.code}</option>
							{/volist}
						</select>

					</div>
				</div>
				<div class="layui-form-item shinfo" style="display: none">
					<label class="layui-form-label">商户姓名 *</label>
					<div class="layui-input-block">
						<input type="text" name="merch_username" lay-filter="username" autocomplete="off"
							placeholder="请输入商户姓名" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item shinfo" style="display: none">
					<label class="layui-form-label">商户手机号码 *</label>
					<div class="layui-input-block">
						<input type="text" name="merch_mobile" lay-filter="mobile" autocomplete="off"
							placeholder="请输入商户手机号码" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">所属部门</label>
					<div class="layui-input-inline">
						<select name="department_id" lay-search="" lay-verify="required">
							<option value="">请选择</option>
							{volist name="department_list" id="t"}
							<option value="{$t.id}">{$t.name}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">缴费类型</label>
					<div class="layui-input-inline">
						<select name="cost_type_id" id="cost_type_list" lay-search="" lay-verify="required"
							lay-filter="cost_type_list" lay-verify="required">
							<option value="0">请选择</option>
							{volist name="cost_type_list" id="t"}
							<option value="{$t.id}">{$t.cost_name}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-form-item" id="sum_number">
					<label class="layui-form-label">办理张数 </label>
					<div class="layui-input-block">
						<input type="text" name="number" id="number" value="1" lay-filter="number" autocomplete="off"
							placeholder="请输入需缴金额" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">缴费列表：</label>
					<div class="layui-input-block">
						<table class="layui-hide" id="student_table" lay-filter="student_table"></table>
					</div>
				</div>
				<!--                <div class="layui-form-item">-->
				<!--                    <label class="layui-form-label">手续费比例：</label>-->
				<!--                    <div class="layui-input-block">-->
				<!--                        <input type="number" name="service_charge_rate" id="service_charge_rate" value="{$service_charge}" lay-filter="service_charge_rate"  lay-verify="required" autocomplete="off" class="layui-input" >-->
				<!--                        <span>%</span>-->
				<!--                    </div>-->
				<!--                </div>-->
				<!--                <div class="layui-form-item">-->
				<!--                    <label class="layui-form-label">手续费：</label>-->
				<!--                    <div class="layui-input-block">-->
				<!--                        <input type="number" name="service_charge" id="service_charge" disabled   lay-verify="required" autocomplete="off" class="layui-input" >-->
				<!--                    </div>-->
				<!--                </div>-->
				<div class="layui-form-item">
					<label class="layui-form-label">总费用 *</label>
					<div class="layui-input-block">
						<input type="text" name="real_amount" disabled="disabled" id="real_amount" lay-verify="required"
							autocomplete="off" placeholder="请输入需缴金额" class="layui-input">
					</div>
				</div>
				<!--                <div id="XM" class="layui-form-item">-->
				<!--                    <label class="layui-form-label">姓名 *</label>-->
				<!--                    <div class="layui-input-block">-->
				<!--                        <input type="text" name="username"  autocomplete="off" placeholder="请输入需姓名" class="layui-input" >-->
				<!--                    </div>-->
				<!--                </div>-->
				<!--                <div id="SJH" class="layui-form-item">-->
				<!--                    <label class="layui-form-label">手机号 *</label>-->
				<!--                    <div class="layui-input-block">-->
				<!--                        <input type="text" name="mobile"  autocomplete="off" placeholder="请输入需手机号" class="layui-input" >-->
				<!--                    </div>-->
				<!--                </div>-->
				<div class="layui-form-item">
					<label class="layui-form-label">有效期</label>
					<div class="layui-input-block">
						<input type="checkbox" name="date_type" checked="checked" lay-skin="switch"
							lay-filter="switchTest" lay-text="长期有效|固定时间">
					</div>
				</div>
				<div class="layui-form-item" style="display: none" id="interval">
					<div class="layui-inline">
						<label class="layui-form-label">日期时间范围</label>
						<div class="layui-input-inline">
							<input type="text" style="width: 400px" class="layui-input" name="date" id="test10"
								placeholder=" 选择时间 ">
						</div>
					</div>
				</div>
				<div style="width: 600px;line-height: 50px;font-weight: 600;">施工人员
					<!-- 	<div class="tianjia" lay-filter="join"
						lay-submit="">添加</div> -->
				</div>
				<!-- <form> -->
					<table class="table" id="formId" lay-filter="demo">
						<thead>

							<tr style=" background-color: #f7f7f7;">
								<th lay-data="{field:'username',width:100}">序号</th>
								<th lay-data="{field:'username',width:100}">姓名</th>
								<th lay-data="{field:'mobile',width:100}">手机号</th>
								<th lay-data="{field:'card_number',width:100}">身份证号</th>
								<th lay-data="{field:'',width:100}">证件照片</th>
								<th lay-data="{field:'',width:100}">操作</th>
							</tr>

						</thead>

						<tbody id="tbodyId">
							<!-- <td><input type="text" name="user" v-model="{$t.id}"></td> -->
							<tr class="removeBox">
								
								<td><input type="text" name="name" lay-verify="required" id="username"></td>
								<td><input type="text" name="phone" lay-verify="required" id="mobile"></td>
								<td><input type="text" name="card" id="card_number"></td>
								<td style="color: #2d8cf0;" onclick="lookImages(this)" id="lookImage">查看</td>
								<td style="font-weight: 600;"><span style="color: #f00;"><span
											onclick="removeInfo(this)" class="removeBtn">移除</span></span></td>
							</tr>
						</tbody>

					</table>
					<div
						style="width: 700px;text-align: right;min-width: 600px;font-size: 13px;font-weight: 600;color: #2d8cf0;line-height: 30px;">
						<span onclick="addPerson1()">+添加施工人员</span>
					</div>
					<!-- {/if} -->
				<!-- 	<div style="width: 210px;margin: 0 0 0 194px;"> <span class="yes" onclick="submi()">提交</span>
						<span class="no" lay-filter="exit" lay-submit>取消</span>
					</div> -->

				<!-- </form> -->
				<div class="maskC" id="mask2" onclick="mask1()">

				</div>
				<div class="layui-carousel swriperC" id="test2">
					<div carousel-item>
						<div>
							<div style="width: 500px;height: 280px;display: inline-block; text-align: center;"
								id="image1"><span
									style="line-height: 280px;color: #ccc;font-size: 12px;">+点击添加身份证正面</span>
							</div>
						</div>
						<div>
							<div style="width: 500px;height: 280px;display: inline-block;text-align: center;"
								id="image2"><span
									style="line-height: 280px;color: #ccc;font-size: 12px;">+点击添加身份证反面</span>
							</div>
						</div>
						<div>
							<div style="width: 500px;height: 280px;display: inline-block;text-align: center;"
								id="image3"><span
									style="line-height: 280px;color: #ccc;font-size: 12px;">+点击添加其他证件</span>
							</div>
						</div>

					</div>
				</div>
				<!--                <div class="layui-form-item">-->
				<!--                    <label class="layui-form-label label-required-next">身份证正面：</label>-->
				<!--                    <div class="layui-input-block">-->
				<!--                        <div class="layui-upload-drag">-->
				<!--                            <img id="is_id_card"  style="width: 260px;margin: 10px 0 10px 0px;height: 150px" src="{if isset($info.id)} {$info.description} {else} __IMG__/default_upload.png {/if}" alt="上传附件" width="120" height="120">-->
				<!--                            <input type="hidden" id="is_id_card_input" name="id_card_positive" value=""   lay-verify="required" lay-verType="tips" lay-reqText="请上传身份证正面~~">-->
				<!--                        </div>-->
				<!--                    </div>-->
				<!--                </div>-->
				<!--                <div class="layui-form-item">-->
				<!--                    <label class="layui-form-label label-required-next">身份证背面：</label>-->
				<!--                    <div class="layui-input-block">-->
				<!--                        <div class="layui-upload-drag">-->
				<!--                            <img id="the_id_card" style="width: 260px;margin: 10px 0 10px 0px;height: 150px"   src="{if isset($info.id)} {$info.description} {else} __IMG__/default_upload.png {/if}" alt="上传附件" width="120" height="120">-->
				<!--                            <input type="hidden" id="the_id_card_input" name="id_card_negative" value=""   lay-verify="required" lay-verType="tips" lay-reqText="请上传身份证背面~~">-->
				<!--                        </div>-->
				<!--                    </div>-->
				<!--                </div>-->
				<!--				<div id="is_card">-->
				<!--					<div class="layui-form-item" id="id_card"style=" position: absolute;width: 50%;left: 500px;bottom: 273px;">-->
				<!--						<label class="layui-form-label label-required-next">其他证件上传：</label>-->
				<!--						<div class="layui-input-block">-->
				<!--							<div class="layui-upload-drag">-->
				<!--								<img id="skill" style="width: 260px;margin: 10px 0 10px 0px;height: 150px"  src="{if isset($info.id)} {$info.description} {else} __IMG__/default_upload.png {/if}" alt="上传附件" width="120" height="120">-->
				<!--								<input type="hidden" id="skill_input" name="other_certificate" value="" >-->
				<!--							</div>-->
				<!--						</div>-->

				<!--					</div>	-->
				<!--				</div>-->

				<!-- 	<div style="width: 210px;margin: 0 0 0 194px;"> <span class="yes" lay-submit lay-filter="adds">提交</span>
						<span class="no" lay-filter="exit" lay-submit>取消</span>
					</div> -->
					<div class="layui-form-item layui-layout-admin " style="width: 100%">
					    <div class="layui-input-block">
					        <div class="layui-footer" style="left: 0px;text-align: center;">
					            <button class="layui-btn" lay-submit lay-filter="add">{:__('Submit')}</button>
					            <button type="button"  class="layui-btn layui-btn-primary">{:__('Reset')}</button>
					        </div>
					    </div>
					</div>
			</form>
		</div>
	</div>
	
</div>

<script>
		var i = 1;
		let number = document.getElementById('number')
		let lookImage = document.getElementById('lookImage')
		let test2 = document.getElementById('test2')
		let mask2 = document.getElementById('mask2')
		let flag
		let personIndex
		// let flagNum = 0
		var newArray = []
		let imageArr = [{
				id_card_positive:'',
				id_card_negativ:'',
				other_certificate:''
			}]
		let submitArray=[]
		let trHtmlString
		window.onload = () => {
			var add = document.getElementById("tbodyId")
			// console.log(flagNum,"flagNum")
			trHtmlString =
				`<tr class="removeBox">\n
					<td>${add.children.length}</td>\n
					<td><input type="text" name="name" lay-verify="required" id="username" ></td>\n
					<td><input type="text" name="phone" lay-verify="required" id="mobile" ></td>\n
					<td><input type="text" name="card" id="card_number"></td>\n
					<td style="color: #2d8cf0;" onclick="lookImages(this)" id="lookImage">上传</td>\n
					<td style="font-weight: 600;"><span style="color: #f00;"><span onclick="removeInfo(this)" class="removeBtn">移除</span></span></td></tr>`
			console.log('wwwwwww', add)
			// var add = document.querySelector("tbody[id='1']")
			add.innerHTML = trHtmlString
			mask2.style.display = "none"
			test2.style.display = "none"
		}
		
		function submi(){
			
			return new Promise((resolve,reject)=>{
				
				resolve(getElementss())
			}).then(res=>{
				console.log(111,newArray)
				for(let i = 0 ; i < newArray.length; i++){
					console.log(222)
					let submitItem = {...newArray[i],...imageArr[i]}
					submitArray.push(submitItem)
					console.log(submitArray)
				}
			})
			
			
			
		}

		function lookImages(e) {
			personIndex = e.parentNode.children[0].innerHTML*1-1
			
			var add = document.getElementById("tbodyId").children
			console.log(add)
			mask2.style.display = "block"
			test2.style.display = "block"
			
			var image1 = document.getElementById('image1')
			var image2 = document.getElementById('image2')
			var image3 = document.getElementById('image3')
			
			if(imageArr[personIndex].id_card_positive != ''){
				image1.innerHTML = `<img id="img1" src="${imageArr[personIndex].id_card_positive}" style="width: 100%; height: 100%;" >`
			}else{
				image1.innerHTML = '<span style="line-height: 280px;color: #ccc;font-size: 12px;">+点击添加身份证正面</span>'
			}
			if(imageArr[personIndex].id_card_negativ != ''){
				image2.innerHTML = `<img id="img2" src="${imageArr[personIndex].id_card_negativ}" style="width: 100%; height: 100%;" >`
			}else{
				image2.innerHTML = '<span style="line-height: 280px;color: #ccc;font-size: 12px;">+点击添加身份证反面</span>'
			}
			if(imageArr[personIndex].other_certificate != ''){
				image3.innerHTML = `<img id="img3" src="${imageArr[personIndex].other_certificate}" style="width: 100%; height: 100%;" >`
			}else{
				image3.innerHTML = '<span style="line-height: 280px;color: #ccc;font-size: 12px;">+点击添加其他证件</span>'
			}
		}
		function showImage(){
			
		}
		
		function imageCreatArr(){
			let imgObj = {
				id_card_positive:'',
				id_card_negativ:'',
				other_certificate:''
			}
			imageArr.push(imgObj)
			console.log(imageArr,'imageArr')
		}

		function mask1() {
			// test2.hide()
			// mask2.hide()
			mask2.style.display = "none"
			test2.style.display = "none"
			// console.log(newArray[personIndex])
			// newArray[personIndex].id_card_positive = id_card_positive
			// newArray[personIndex].id_card_negativ = id_card_negativ
			// newArray[personIndex].other_certificate = other_certificate
			
			console.log(newArray)
			id_card_positive = ''
			id_card_negativ = ''
			other_certificate = ''
		}

		function addF(num) {
			var add = document.getElementById("tbodyId")
			let addString = ''
			addString += trHtmlString
			return addString
		}
		var removeBtn = document.getElementsByClassName('removeBtn')
		var removeBox = document.getElementsByClassName('removeBox')

		function addPerson1() {
			imageCreatArr()
			var add = document.getElementById("tbodyId")
			
			let tr = document.createElement("tr")
			console.log(add, tr, add.children.length)
			add.appendChild(tr)
			number.value = add.children.length
			console.log(add)
			console.log(add.children)
			// console.log(add.children.length,flagNum,"flagNum")
				trHtmlString =
					`<tr class="removeBox">\n
						<td>${add.children.length}</td>\n
						<td><input type="text" name="name" lay-verify="required" id="username" ></td>\n
						<td><input type="text" name="phone" lay-verify="required" id="mobile" ></td>\n
						<td><input type="text" name="card" id="card_number"></td>\n
						<td style="color: #2d8cf0;" onclick="lookImages(this)" id="lookImage">上传</td>\n
						<td style="font-weight: 600;"><span style="color: #f00;"><span onclick="removeInfo(this)" class="removeBtn">移除</span></span></td></tr>`
			tr.innerHTML = trHtmlString
			
		}

		function delPerson() {
			
			var add = document.getElementById("tbodyId")
			
			console.log(add.children, add.children.length)
			add.removeChild(add.children[add.children.length - 1])
			number.value = add.children.length
			
		}



		number.onblur = () => {
			var add = document.getElementById("tbodyId")
			let a = (number.value * 1) - add.children.length
			if (a > 0) {
				for (let i = 1; i <= a; i++) {
					addPerson1()
				}
			} else if (a < 0) {
				for (let i = -1; i >= a; i--) {
					delPerson()
				}
			}
			flag = number.value * 1
		}

		for (let i in removeBtn) {
			removeBtn[i].onclick = () => {
				removeBox[i].innerHTML = ``
			}
		}

		function removeInfo(e) {
			// alert('1')
			var add = document.getElementById("tbodyId")
			console.log(e.parentNode.parentNode.parentNode.children[0].innerHTML,'aaa')
			let delNum = e.parentNode.parentNode.parentNode.children[0].innerHTML*1-1
			e.parentNode.parentNode.parentNode.remove()
			console.log(removeBtn.length)
			
			number.value = removeBtn.length
			
			for(let i = 0 ;i < add.children.length; i++){
				console.log(add.children[i].children[0].innerHTML*1,delNum)
				if(add.children[i].children[0].innerHTML*1 > delNum){
					add.children[i].children[0].innerHTML = add.children[i].children[0].innerHTML*1-1
				}
			}
			
			newArray.splice(personIndex,1)
			imageArr.splice(personIndex,1)
			submitArray.splice(personIndex,1)
			
			
			
			
			
			// console.log(1111111)
			// $.ajax({
			// 	url: "{:url('remove')}", 
			// 	type: "post",
			// 	data: {
			// 		'id': e
			// 	},
			// 	dataType: "json",
			// 	success: function(data) {
			// 		layer.msg("移除成功", {
			// 			icon: 5,
			// 			time: 1000
			// 		});
			// 	}
			// });
		}
		
		function getElementIndex(){
			var child = document.getElementById("a");
			var parent = child.parentNode;
			var index = Array.prototype.indexOf.call(parent,child);
			console.log(index)//1
			
		}


		
		function getElementss() {
			console.log('999999999999')
			// 获取form表单
			var form = document.getElementById('formId')
			console.log(form)
			// 创建一个新数组
			var elements = new Array();
			// 获取所有input标签
			var tagElements = form.getElementsByTagName('input');
			// 将所有input标签放入数组
			console.log(tagElements)
			for(let i = 0; i<tagElements.length; i++){
				elements.push(tagElements[i]);
				// console.log(elements)
			}
			console.log(elements)
			let newObj = {}
			for (let j = 0; j < tagElements.length; j++) {
				let newName = elements[j].id
				let newValue = elements[j].value
				// 如果name等于最后一个input的name  则将这个对象存入数组 并重新复制新对象为空
				if (newName == 'username') {
					newObj.username = newValue
				}
				if (newName == 'mobile') {
					newObj.mobile = newValue
				}
				if (newName == 'card_number') {
					newObj.card_number = newValue
				}

				if (newName == 'card_number') {
					newArray.push(newObj)
					newObj = {}
				}
			}
			console.log(newArray,'111')
			return
		}
		

		layui.use(['element', 'form', 'table', 'jquery', 'lucky', 'upload', 'laydate', 'xmSelect', 'carousel'], function() {
			var element = layui.element;
			var table = layui.table;
			var form = layui.form;
			var laydate = layui.laydate;
			var upload = layui.upload;
			var $ = layui.jquery;
			var lucky = layui.lucky;
			var carousel = layui.carousel;
			let costTypeNum
			let newUpDataObj = []
			let marchType
			let marchId
			let newNumber = 1
			let newRealAmount = 0
			laydate.render({
				elem: '#test10',
				type: 'datetime',
				range: true,
				trigger: 'click'
			});
			form.on('select(merchant_id)', function(data) {
				var id = data.value;
				marchId = data.value
				// if (type == 1) {
				// 	$(".shinfo").css('display', 'none');
				// 	$(".merch").css('display', 'block');
				// } else {
				// 	$(".shinfo").css('display', 'block');
				// 	$(".merch").css('display', 'none');
				// }
			});
			form.on('select(merchant_type)', function(data) {
				var type = data.value;
				marchType = data.value
				if (type == 1) {
					$(".shinfo").css('display', 'none');
					$(".merch").css('display', 'block');
				} else {
					$(".shinfo").css('display', 'block');
					$(".merch").css('display', 'none');
				}
			});



			// $("#addPerson1").click(function(){
			// 	// addPerson1()
			// 	alert('11111')
			// });
			var costType = [];
			var student_table = table.render({
				id: 'student_table',
				elem: '#student_table',
				cols: [
					[{
							field: 'cost_name',
							title: '收费名称'
						},
						{
							field: 'type',
							title: '收费类型',
							templet: function(item) {
								var type = item.type
								if (type == 1) {
									return '押金'
								} else if (type == 2) {
									return '费用'
								} else if (type == 3) {
									return '证件'
								} else {
									return '未知类型'
								}
							}
						},
						{
							title: '单价',
							field: 'unitprice',
							edit: true
						},
						{
							title: '税率',
							field: 'tax_rate'
						},
						{
							title: '税率金额',
							field: 'tax_money'
						},
						{
							title: '收入金额',
							field: 'money'
						},
						{
							title: '总金额',
							field: 'z_money'
						},
					]
				],
				data: costType
			});
			table.on('edit(student_table)', function(obj){
				console.log(obj,1111)
				
			    var real_amount = 0;
			    var value = obj.value //得到修改后的值
			        ,data = obj.data //得到所在行所有键值
			        ,field = obj.field; //得到字段
			    console.log('value',value)
			    var param  = layui.table.cache["student_table"]
			    for ( var i=0;i<param.length;i++){
			        real_amount += parseFloat(param[i].amount);
			    }
			    student_table.reload(param);
			    $("#amount").val(parseFloat(real_amount));    
				var number = $("#number").val();
				var datas = {};
				datas.number = number; //  购买数量
				datas.cost_type = costTypeNum; // 缴费类型
				for(let i=0;i<newUpDataObj.length;i++){
					let newKey
					for(let key in newUpDataObj[i]){
						newKey = key
					}
					
					console.log(obj.data.id,newUpDataObj[i],obj.value*1,newKey*1)
					if(obj.data.id*1 == newKey*1){
						console.log('进来了')
						newUpDataObj[i][obj.data.id] = obj.value*1
					}
				}
				datas.update = newUpDataObj
				
				newUpDataObj = []
				
				
				costtype(datas);
			});
			form.on('switch(switchTest)', function(data) {
				if (this.checked == false) {
					$('#interval').css('display', 'block')
				} else {
					$('#interval').css('display', 'none')
				}
			});

			// cost_type_list
			form.on('select(cost_type_list)', function(data) {
				student_table.reload({
					data: []
				});
				if (!data.value) {
					return false
				}
				var number = $("#number").val();
				if (!number) {
					layer.msg("请先填写购买数量", {
						icon: 15,
						time: 1000,
						shade: 0.3
					});
					return false;
				}
				var datas = {};
				datas.number = number; //  购买数量
				datas.cost_type = data.value; // 缴费类型
				costTypeNum = data.value
				
				costtype(datas);
				return false;
			});

			function costtype(datas) {
				$.ajax({
					url: "{:url('getCostType')}",
					type: "post",
					data: datas,
					dataType: "json",
					success: function(data) {
						if (data.code == 0) {
							var param = data.data
							$("#real_amount").val(param.z_money);
							student_table.reload({
								data: param.data
							});
							console.log(param,122121)
							for(let i = 0; i < param.data.length; i++){
								
								let paramObj = {
									[param.data[i].id]:param.data[i].unitprice
								}
								newUpDataObj.push(paramObj)
							}
							if (param.is_card == 1) {
								$('#id_card').css('display', 'block')
								// $('#XM').css('display','none')
								// $('#SJH').css('display','none')
							} else {
								$('#id_card').css('display', 'none')
								// $('#XM').css('display','block')
								// $('#SJH').css('display','block')
							}
						} else {
							layer.msg(data.msg, {
								icon: 15,
								time: 1000,
								shade: 0.3
							});
							student_table.reload({
								data: []
							});
						}
					}
				});
			}

			$("#number").on("input", function(e) {
				newNumber = e.delegateTarget.value
				console.log('1111111111')
				student_table.reload({
					data: []
				});
				if (!e.delegateTarget.value) {
					return false
				}
				var cost_type = $("#cost_type_list").val();
				if (!cost_type) {
					return false;
				}
				var datas = {};
				datas.number = e.delegateTarget.value; //  购买数量
				datas.cost_type = cost_type; // 缴费类型
				costtype(datas);
				newUpDataObj = []
				return false;
			});
			// form.on('select(certificate_type)', function(data){
			//     console.log(data.value)
			//     if (data.value == 2 ){
			//         $('#sum_number').css('display','block')
			//         $('#id_card').css('display','block')
			//     }else if (data.value == 1) {
			//         $('#number').val(1)
			//         $('#sum_number').css('display','none')
			//         $('#id_card').css('display','none')
			//     }
			//     var  cost_type = $("#cost_type_list").val();
			//     if (!cost_type){
			//         return false;
			//     }
			//     var  number = $("#number").val();
			//     if (!number){
			//         return false;
			//     }
			//     var datas = {} ;
			//     datas.number      = number;   //  购买数量
			//     datas.cost_type   = cost_type ;   // 缴费类型
			//     costtype(datas) ;
			//     return false;
			// });
			upload.render({
				elem: '#image1',
				url: "{:url('common/UpImg')}" //图片上传地址
					,
				accept: 'images' //
					,
				acceptMime: 'image/*',
				size: 1024 * 12,
				before: function(res) {
					loading = layer.load(2, {
						shade: [0.2, '#000'] //0.2透明度的白色背景
					});
				},
				done: function(data) {
					var image1 = document.getElementById('image1')
					image1.innerHTML = ` <img id="img1" src="" style="width: 100%; height: 100%;" >`
					layer.close(loading);
					if (data.code == 1) {
						console.log(data)
						imageArr[personIndex].id_card_positive= data.data.thumb_path
						$("#img1").attr("src", data.data.thumb_path);
						layer.msg('图片上传成功', {
							icon: 1,
							time: 1000
						});
					} else {
						layer.msg(data.msg, {
							icon: 5,
							time: 1000
						});
					}
				},
				error: function(red) {
					layer.close(loading);
					layer.msg("网络错误", {
						icon: 5,
						time: 1500
					});
				}
			});
			upload.render({
				elem: '#image2',
				url: "{:url('common/UpImg')}" //图片上传地址
					,
				accept: 'images' //
					,
				acceptMime: 'image/*',
				size: 1024 * 12,
				before: function(res) {
					loading = layer.load(2, {
						shade: [0.2, '#000'] //0.2透明度的白色背景
					});
				},
				done: function(data) {
					var image2 = document.getElementById('image2')
					image2.innerHTML = ` <img id="img2" src="" style="width: 100%; height: 100%;" >`
					layer.close(loading);
					if (data.code == 1) {
						console.log(data)
						imageArr[personIndex].id_card_negativ = data.data.thumb_path
						$("#img2").attr("src", data.data.thumb_path);
						layer.msg('图片上传成功', {
							icon: 1,
							time: 1000
						});
					} else {
						layer.msg(data.msg, {
							icon: 5,
							time: 1000
						});
					}
				},
				error: function(red) {
					layer.close(loading);
					layer.msg("网络错误", {
						icon: 5,
						time: 1500
					});
				}
			});
			upload.render({
				elem: '#image3',
				url: "{:url('common/UpImg')}" //图片上传地址
					,
				accept: 'images' //
					,
				acceptMime: 'image/*',
				size: 1024 * 12,
				before: function(res) {
					loading = layer.load(2, {
						shade: [0.2, '#000'] //0.2透明度的白色背景
					});
				},
				done: function(data) {
					var image3 = document.getElementById('image3')
					image3.innerHTML = ` <img id="img3" src="" style="width: 100%; height: 100%;" >`
					layer.close(loading);
					if (data.code == 1) {
						console.log(data)
						imageArr[personIndex].other_certificate = data.data.thumb_path
						$("#img3").attr("src", data.data.thumb_path);
						layer.msg('图片上传成功', {
							icon: 1,
							time: 1000
						});
					} else {
						layer.msg(data.msg, {
							icon: 5,
							time: 1000
						});
					}
				},
				error: function(red) {
					layer.close(loading);
					layer.msg("网络错误", {
						icon: 5,
						time: 1500
					});
				}
			});

			carousel.render({
				elem: '#test2',
				width: '100%' //设置容器宽度
				,autoplay:false,
				arrow: 'none',
			});
			// 表单赋值
			var info = {:json_encode($info)};
			form.val("form", info);
			console.log(info,'infoinfoinfoinfoinfo')
			form.on('submit(add)', function(data) {
				let newreal_amount = document.getElementById('real_amount').value
				submi().then(res=>{
					console.log(111)
					console.log(submitArray,typeof submitArray,999999)
					var datas = layui.table.cache["student_table"]
					
					console.log(data,datas,'datafalimey')
					data.field.type = 3 // 添加type
					data.field.is_admin_create = 0 // 添加type
					data.field.pay_status = 0 // 支付状态
					data.field.datas = datas // 添加type
					data.field.personArray = submitArray
					// let newUpData = {
					// 	type:3,
					// 	is_admin_create:0,
					// 	pay_status:0,
					// 	datas:datas,
					// 	personArray:submitArray,
					// 	merchant_type:marchType,
					// 	number:newNumber,
					// 	real_amount:newreal_amount,
					// 	merchant_id:marchId
					// }
					lucky.FormSubmit("{:url('add')}", data.field, true);
					submitArray = []
					// var index = parent.layer.getFrameIndex(window.name);
					// setTimeout(function(){}, 2000);
					// layer.msg("网络错误", {
					// 	icon: 5,
					// 	time: 1500
					// });
					
					return false;
				})
				
			});
		})
	</script>

{/block}
